﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_userrightInfo
    {
        private int _form_id;
        private int _groupid;
        private int _loadform;
        private int _savedata;
        private int _updatedata;
        private int _deletedata;
        private int _printreport;
        private int _identify;
        private int _othercmd;

        public cs_hmr_userrightInfo()
        {
            this._form_id = 0;
            this._groupid = 0;
            this._loadform = 0;
            this._savedata = 0;
            this._updatedata = 0;
            this._deletedata = 0;
            this._printreport = 0;
            this._identify = 0;
            this._othercmd = 0;

        }
        public int form_id
        {
            get
            {
                return this._form_id;
            }
            set
            {
                this._form_id = value;
            }
        }
        public int groupid
        {
            get
            {
                return this._groupid;
            }
            set
            {
                this._groupid = value;
            }
        }
        public int loadform
        {
            get
            {
                return this._loadform;
            }
            set
            {
                this._loadform = value;
            }
        }
        public int savedata
        {
            get
            {
                return this._savedata;
            }
            set
            {
                this._savedata = value;
            }
        }
        public int updatedata
        {
            get
            {
                return this._updatedata;
            }
            set
            {
                this._updatedata = value;
            }
        }
        public int deletedata
        {
            get
            {
                return this._deletedata;
            }
            set
            {
                this._deletedata = value;
            }
        }
        public int printreport
        {
            get
            {
                return this._printreport;
            }
            set
            {
                this._printreport = value;
            }
        }
        public int identify
        {
            get
            {
                return this._identify;
            }
            set
            {
                this._identify = value;
            }
        }
        public int othercmd
        {
            get
            {
                return this._othercmd;
            }
            set
            {
                this._othercmd = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[10];
            paraName[0] = "@form_id";
            paraName[1] = "@groupid";
            paraName[2] = "@loadform";
            paraName[3] = "@savedata";
            paraName[4] = "@updatedata";
            paraName[5] = "@deletedata";
            paraName[6] = "@printreport";
            paraName[7] = "@identify";
            paraName[8] = "@othercmd";
            paraName[9] = "@option";
            object[] paraValue = new object[10];
            paraValue[0] = this._form_id;
            paraValue[1] = this._groupid;
            paraValue[2] = this._loadform;
            paraValue[3] = this._savedata;
            paraValue[4] = this._updatedata;
            paraValue[5] = this._deletedata;
            paraValue[6] = this._printreport;
            paraValue[7] = this._identify;
            paraValue[8] = this._othercmd;
            paraValue[9] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 10, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[9];
            fields[0] = "form_id";
            fields[1] = "groupid";
            fields[2] = "loadform";
            fields[3] = "savedata";
            fields[4] = "updatedata";
            fields[5] = "deletedata";
            fields[6] = "printreport";
            fields[7] = "identify";
            fields[8] = "othercmd";
            list.KetDulieu(myList, "HMR_UserRight", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_UserRight", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("groupid", "form_id");
            cb.KetDuLieu(cbo, "HMR_UserRight", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[9];
            header[0] = "form_id";
            header[1] = "groupid";
            header[2] = "loadform";
            header[3] = "savedata";
            header[4] = "updatedata";
            header[5] = "deletedata";
            header[6] = "printreport";
            header[7] = "identify";
            header[8] = "othercmd";

            string[] mappingname = new string[9];
            mappingname[0] = "form_id";
            mappingname[1] = "groupid";
            mappingname[2] = "loadform";
            mappingname[3] = "savedata";
            mappingname[4] = "updatedata";
            mappingname[5] = "deletedata";
            mappingname[6] = "printreport";
            mappingname[7] = "identify";
            mappingname[8] = "othercmd";

            int[] colwidth = new int[9];
            colwidth[0] = 12;
            colwidth[1] = 12;
            colwidth[2] = 12;
            colwidth[3] = 12;
            colwidth[4] = 12;
            colwidth[5] = 12;
            colwidth[6] = 12;
            colwidth[7] = 12;
            colwidth[8] = 12;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_UserRight", datagrid, csdl.OpenTable("HMR_UserRight", condition), header, mappingname, colwidth, 9);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_UserRight", "form_id = " + this._form_id + " and groupid = " + this._groupid );
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._form_id = Convert.ToInt32(ds.Tables[0].Rows[0]["form_id"].ToString().Trim());
                this._groupid = Convert.ToInt32(ds.Tables[0].Rows[0]["groupid"].ToString().Trim());
                this._loadform = Convert.ToInt32(ds.Tables[0].Rows[0]["loadform"].ToString().Trim());
                this._savedata = Convert.ToInt32(ds.Tables[0].Rows[0]["savedata"].ToString().Trim());
                this._updatedata = Convert.ToInt32(ds.Tables[0].Rows[0]["updatedata"].ToString().Trim());
                this._deletedata = Convert.ToInt32(ds.Tables[0].Rows[0]["deletedata"].ToString().Trim());
                this._printreport = Convert.ToInt32(ds.Tables[0].Rows[0]["printreport"].ToString().Trim());
                this._identify = Convert.ToInt32(ds.Tables[0].Rows[0]["identify"].ToString().Trim());
                this._othercmd = Convert.ToInt32(ds.Tables[0].Rows[0]["othercmd"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.form_id, b.tenform, b.ghichu, a.savedata, a.updatedata, a.deletedata, a.printreport"
                        + " from HMR_UserRight a, HMR_WINFORM b"
                        + " where a.form_id = b.formid and a.groupid = " + this._groupid;
                ds = csdl.SelecSQL(sql);
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
